package com.yungu.swift.admin.base;

import com.yungu.swift.base.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;

/**
 * @author : cuixiuyin
 * @date : 2019/7/31
 */
@Slf4j
@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ExceptionAdvice {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseData<Void> handleException(Exception ex) {
        log.error("admin route error.", ex);
        return ResponseData.buildErrorResponse(INTERNAL_SERVER_ERROR.value(), "服务器异常，请稍后再试", null);
    }
}
